Skip to content

gh-145413: Fix nested attribute suggestions executing property code#145414

Closed
Hiumee wants to merge 3 commits intopython:mainfrom
Hiumee:fix-issue-145413
Closed

gh-145413: Fix nested attribute suggestions executing property code#145414
Hiumee wants to merge 3 commits intopython:mainfrom
Hiumee:fix-issue-145413

Conversation

@Hiumee
Copy link
Copy Markdown

@Hiumee Hiumee commented Mar 2, 2026

Updated the code of _check_for_nested_attribute to check properties without triggering their code. This approach will still suggest them

Changed a test case to look for side effects and changed some contradictory comments

Updated the news section code to include imports so the code can be tested out of the box

Example

from dataclasses import dataclass
from math import pi

@dataclass
class Circle:
   radius: float
   @property
   def area(self) -> float:
      print("Property 'area' accessed")
      return pi * self.radius**2

class Container:
   def __init__(self, inner: Circle) -> None:
      self.inner = inner

circle = Circle(radius=4.0)
container = Container(circle)
print(container.area)

Output

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    print(container.area)
          ^^^^^^^^^^^^^^
AttributeError: 'Container' object has no attribute 'area'. Did you mean '.inner.area' instead of '.area'?

It doesn't reach the print statement at all


📚 Documentation preview 📚: https://cpython-previews--145414.org.readthedocs.build/

@Hiumee Hiumee requested a review from AA-Turner as a code owner March 2, 2026 11:41
@python-cla-bot
Copy link
Copy Markdown

python-cla-bot bot commented Mar 2, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@johnslavik johnslavik requested review from johnslavik March 2, 2026 14:15
@Hiumee
Copy link
Copy Markdown
Author

Hiumee commented Mar 26, 2026

Appears to be fixed by #146188
Would the test case in the PR still be useful to prevent regression?

Edit: It seems the new test case covers it. I'll close the issue and PR

@Hiumee Hiumee closed this Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant